package cn.tedu.system.order.controller;

import cn.tedu.system.base.response.JsonResult;
import cn.tedu.system.order.pojo.dto.OrderCreateRequestDto;
import cn.tedu.system.order.pojo.dto.OrderPageDto;
import cn.tedu.system.order.pojo.dto.OrderReviseDto;
import cn.tedu.system.order.pojo.dto.OrderStatusParam;
import cn.tedu.system.order.pojo.vo.OrderItemVO;
import cn.tedu.system.order.pojo.vo.OrderVO;
import cn.tedu.system.order.service.OrderService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@Api(tags = "04.订单模块")
@RestController
@RequestMapping("/api/v1/order/")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("用户创建订单功能")
    @ApiOperationSupport(order = 10)
    @PostMapping("private/create")
    public JsonResult create(@RequestBody OrderCreateRequestDto request, @ApiIgnore HttpSession session) {
        log.debug("创建订单参数:{}",request);
        orderService.createOrder(request,session);
        return JsonResult.ok();
    }

    @ApiOperation("直播创建的订单")
    @ApiOperationSupport(order = 15)
    @PostMapping("private/createLive")
    public JsonResult createLive(@RequestBody OrderCreateRequestDto request, @ApiIgnore HttpSession session) {
        log.debug("创建直播订单参数:{}",request);
        orderService.createLiveOrder(request,session);
        return JsonResult.ok();
    }

    @ApiOperation("用户修改订单状态功能")
    @ApiOperationSupport(order = 20)
    @PostMapping("private/revise")
    public JsonResult revise(@RequestBody OrderReviseDto orderReviseDto, @ApiIgnore HttpSession session) {
        log.debug("用户信息修改参数:{}",orderReviseDto);
        orderService.reviseOrder(orderReviseDto,session);
        return JsonResult.ok();
    }

    @ApiOperation("用户删除订单功能")
    @ApiOperationSupport(order = 30)
    @PostMapping("public/delete")
    public JsonResult delete(@RequestBody OrderReviseDto orderReviseDto, @ApiIgnore HttpSession session) {
        log.debug("删除订单参数:{}",orderReviseDto);
        orderService.delete(orderReviseDto,session);
        return JsonResult.ok();
    }

    @ApiOperation("用户查询订单状态功能")
    @ApiOperationSupport(order = 40)
    @GetMapping("public/select")
    public JsonResult select(Integer status, @ApiIgnore HttpSession session) {
        log.debug("查询订单参数:{}",status);
        List<OrderVO> list = orderService.select(status,session);
        return JsonResult.ok(list);
    }

    @ApiOperation("用户查询所有订单功能")
    @ApiOperationSupport(order = 50)
    @GetMapping("public/selectAll")
    public JsonResult selectAll(@ApiIgnore HttpSession session) {
        log.debug("controller类查所有订单");
        List<OrderVO> list = orderService.selectAll(session);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询订单数量功能")
    @ApiOperationSupport(order = 60)
    @GetMapping("total")
    public JsonResult total(@ApiIgnore HttpSession session) {
        log.debug("查订单总数");
        int total = orderService.selTotal(session);
        return JsonResult.ok(total);
    }

    //yangping
    @ApiOperation("商家查询订单功能")
    @ApiOperationSupport(order = 65)
    @GetMapping("getOrders")
    public JsonResult orders(Long merchantId, @ApiIgnore HttpSession session) {
        log.debug("商家查询订单参数:{}",merchantId);
        List<OrderVO> list = orderService.getOrders(merchantId,session);
        log.debug("商家查询订单结果:{}",list);
        return JsonResult.ok(list);
    }

    @ApiOperation("商家发货功能")
    @ApiOperationSupport(order = 70)
    @PostMapping("private/shipments")
    public JsonResult shipments(@RequestBody OrderStatusParam orderParam, @ApiIgnore HttpSession session) {
        log.debug("商家发货订单参数: {}",orderParam);
        orderService.shipments(orderParam,session);
        return JsonResult.ok();
    }

    @ApiOperation("查看订单详情")
    @ApiOperationSupport(order = 80)
    @GetMapping("detail")
    public JsonResult detail(Long orderId, @ApiIgnore HttpSession session) {
        log.debug("查看订单详情参数:{}",orderId);
        List<OrderItemVO> list = orderService.selOrderDetail(orderId,session);
        return JsonResult.ok(list);
    }

//    @ApiOperation("商家查询自己店铺订单功能")
//    @ApiOperationSupport(order = 90)
//    @GetMapping("merchantGetStoreOrders")
//    public JsonResult merchantGetStoreOrders(Long merchantId, @ApiIgnore HttpSession session) {
//        log.debug("商家查询自己店铺订单参数:{}",merchantId);
//        List<OrderVO> list = orderService.merchantGetOrders(merchantId,session);
//        return JsonResult.ok(list);
//    }
}
